<template xmlns="http://www.w3.org/1999/html">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="用户账号" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入用户账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入用户邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择用户性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="帐号状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择帐号状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="证件号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入证件号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="真实姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入真实姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-row :gutter="20" class="card-list" v-loading="loading">
      <el-col
        v-for="(item, index) in managementList"
        :key="index"
        :span="4"
        class="card-col"
      >
        <el-card class="customer-card" shadow="hover">
          <div slot="header" class="card-header">
            <span class="customer-name">{{ item.realName }}</span>
            <el-tag :type="item.sex == 0 ? 'primary' : 'danger'" size="mini">
              {{ item.sex == 0 ? '男' : '女' }}
            </el-tag>
          </div>

          <div class="card-body">
            <div class="avatar-container">
              <el-avatar
                shape="circle"
                :size="60"
                :fit="'cover'"
                :src="item.avatar"
                class="customer-avatar"
              >
                <img src="@/assets/images/profile.jpg" alt="默认头像" />
              </el-avatar>
            </div>

            <div class="customer-info">
              <ul class="info-list">
                <li class="info-item">
                  <i class="el-icon-phone info-icon"></i>
                  <span class="info-value">{{ item.phoneNumber || '未填写' }}</span>
                </li>
                <li class="info-item">
                  <i class="el-icon-message info-icon"></i>
                  <span class="info-value">{{ item.email || '未填写' }}</span>
                </li>
                <li class="info-item">
                  <i class="el-icon-location-information info-icon"></i>
                  <span class="info-value address-value" :title="item.address || '未填写'">
                    {{ item.address || '未填写' }}
                  </span>
                </li>
              </ul>
            </div>
          </div>

          <div class="card-footer">
            <el-button
              type="primary"
              size="mini"
              plain
              @click="$router.push('/customer/health-detail/index/' + item.id)"
              icon="el-icon-monitor"
            >
              数字人
            </el-button>
            <el-button
              type="primary"
              size="mini"
              plain
              @click="$router.push('/customer/health-report/index/' + item.id)"
              icon="el-icon-monitor"
            >
              健康报告
            </el-button>
            <el-button
              type="primary"
              size="mini"
              plain
              @click="$router.push('/customer/health-timeBase/index/' + item.id)"
              icon="el-icon-monitor"
            >
              时间轴
            </el-button>
            <el-button
              type="success"
              size="mini"
              plain
              @click="$router.push('/health/healthReport/index/' + item.id+'/'+item.realName)"
              icon="el-icon-notebook-2"
            >
              历史报告
            </el-button>
            <el-button
              type="info"
              size="mini"
              plain
              @click="$router.push('/customer/management-detail/index/' + item.id)"
              icon="el-icon-document"
            >
              档案
            </el-button>
          </div>
        </el-card>
      </el-col>

      <!-- 空状态 -->
      <el-col v-if="managementList.length === 0 && !loading" :span="24">
        <el-empty description="暂无客户数据" :image-size="200"></el-empty>
      </el-col>
    </el-row>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :pageSizes="[12,18,24,30,36,42,48]"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listManagement } from '@/api/customer/management'

export default {
  name: 'Health',
  dicts: ['sys_user_sex', 'sys_normal_disable', 'id_type', 'delete_flag'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户管理表格数据
      managementList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      accountOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 24,
        deptId: null,
        account: null,
        nickName: null,
        email: null,
        phoneNumber: null,
        sex: null,
        avatar: null,
        status: null,
        idType: null,
        idNumber: null,
        guardianName: null,
        guardianPhone: null,
        address: null,
        realName: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询客户管理列表 */
    getList() {
      this.loading = true
      listManagement(this.queryParams).then(response => {
        this.managementList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>

<style scoped lang="scss">
.app-container {
  background-color: #f5f7fa;
  min-height: calc(100vh - 84px);
  padding: 15px;
}

.card-list {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -8px;
}

.card-col {
  margin-bottom: 16px;
  padding: 0 8px;
  box-sizing: border-box;
}

.customer-card {
  height: 100%;
  border-radius: 6px;
  overflow: hidden;
  transition: all 0.3s ease;
  box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.1);

  &:hover {
    transform: translateY(-3px);
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.15);
  }
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background-color: #ffffff;
  border-bottom: 1px solid #ebeef5;

  .customer-name {
    font-size: 14px;
    font-weight: 600;
    color: #303133;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.card-body {
  padding: 12px;
  background-color: #fafafa;
}

.avatar-container {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.customer-avatar {
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.customer-info {
  .info-list {
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .info-item {
    display: flex;
    align-items: flex-start;
    margin-bottom: 8px;
    padding: 4px 0;

    &:last-child {
      margin-bottom: 0;
    }
  }

  .info-icon {
    font-size: 12px;
    color: #409eff;
    margin-right: 5px;
    flex-shrink: 0;
    margin-top: 2px;
  }

  .info-value {
    color: #303133;
    font-size: 12px;
    flex: 1;
    word-break: break-all;
  }

  .address-value {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.card-footer {
  display: flex;
  justify-content: space-between;
  padding: 8px;
  background-color: #ffffff;
  border-top: 1px solid #ebeef5;
  flex-wrap: wrap;

  .el-button {
    flex: 1;
    margin: 2px;
    font-size: 12px;
    padding: 6px 4px;
    min-width: calc(50% - 4px);

    &:first-child {
      margin-left: 2px;
    }

    &:last-child {
      margin-right: 2px;
    }
  }
}

// 响应式设计
@media (max-width: 1600px) {
  .card-col {
    width: 20%; // 5列
  }
}

@media (max-width: 1400px) {
  .card-col {
    width: 25%; // 4列
  }
}

@media (max-width: 1200px) {
  .card-col {
    width: 33.333%; // 3列
  }
}

@media (max-width: 992px) {
  .card-col {
    width: 50%; // 2列
  }
}

@media (max-width: 768px) {
  .card-col {
    width: 100%; // 1列
  }

  .card-footer {
    flex-direction: row;

    .el-button {
      margin: 2px;
    }
  }
}

@media (max-width: 1100px) and (min-width: 993px) {
  .card-footer {
    .el-button {
      min-width: calc(33.33% - 4px);
    }
  }
}

@media (max-width: 1280px) and (min-width: 1201px) {
  .card-footer {
    .el-button {
      min-width: calc(33.33% - 4px);
    }
  }
}

@media (max-width: 1366px) and (min-width: 1281px) {
  .card-footer {
    .el-button {
      min-width: calc(33.33% - 4px);
      padding: 5px 3px;
      font-size: 11px;
    }
  }
}

@media (max-width: 1440px) and (min-width: 1367px) {
  .card-footer {
    .el-button {
      min-width: calc(33.33% - 4px);
      padding: 5px 3px;
      font-size: 11px;
    }
  }
}

// 搜索表单优化
.el-form {
  background-color: #ffffff;
  padding: 12px;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 12px;
}

.el-form-item {
  margin-bottom: 8px !important;
}

// 分页组件优化
.pagination-container {
  margin-top: 15px;
  padding: 12px;
  border-radius: 4px;
  background-color: transparent !important;
}
</style>
